<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>">
		<!--[if lte IE 6]></base><![endif]-->
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="keywords"
			content="学生综合信息管理平台,学生,综合,信息,管理,管理平台,学生综合,综合信息,学生平台,广东科学技术职业学院,科干,管理平台,学生信息管理,信息管理平台,学生信息网站,学生信息管理网站,科学技术,广科,广科院,广科院学生信息管理,广科院学生综合信息" />
		<title>学生综合信息管理平台</title>
		<link href="images/logo-copy.ico" rel="shortcut icon"
			type="image/x-icon" />
		<link href="css/menu.css" rel="stylesheet" type="text/css" />
		<link href="css/index.css" rel="stylesheet" type="text/css" />
		<link href="css/jquery-ui-1.8.16.custom.css" rel="stylesheet"
			type="text/css" />
		<link href="css/paging.css" rel="stylesheet" type="text/css" />
		<script language="javascript" type="text/javascript"
			src="javascript/jquery-1.6.4.js">
</script>
		<script language="javascript" type="text/javascript"
			src="javascript/jquery-ui-1.8.16.custom.min.js">
</script>
		<script language="javascript" type="text/javascript"
			src="javascript/jquery.bgiframe.js">
</script>
		<script language="javascript" type="text/javascript"
			src="javascript/common.js" charset="gb18030">
</script>

		<script type='text/javascript' src='dwr/interface/attendanceAction.js'>
</script>

		<script type='text/javascript' src='dwr/engine.js'>
</script>

		<script type='text/javascript' src='dwr/util.js'>
</script>


		<script language="javascript" type="text/javascript">

var className = null;//班级名称
var studentName = null;//学生名称
var studentNumber = null;//学号
var lineNumber = null;//数据条数
//var classNameVo = null;
/*var weekCounts = null;//周次
 var lateCounts = null;//迟到次数
 var truancyCounts = null;//旷课次数
 var leaveEarlyCounts = null;//早退次数
 var leaveCounts = null;//请假次数
 */

//限制文本框只能输入 数字
$(function() {
	checkNumberInput($("#weekId"));
	checkNumberInput($("#lateId"));
	checkNumberInput($("#leaveEarlyId"));
	checkNumberInput($("#truancyId"));
	checkNumberInput($("#leaveId"));
	checkNumberInput($("#studentInfo"));

	/*使用autocomplete方法 可以取到班级、学号、姓名的值（有提示作用） */
	attendanceAction.gainAllClassNameForSelect(function(data) {
		$("#className").autocomplete( {
			source : data,
			select : function(event, ui) {
				$("#className").val(ui.item.value)
				className = ui.item.value;
				return false;
			}
		})
	})

})
/*初使化自动提示框*/
function initStudentSelect() {
	if ($.trim($("#className").val()) == "") {
		$("#studentInfo").val("")
		alert("请先输入班级");
		return;
	}
	attendanceAction.gainStudentVoForSelect(null, function(data) {
		data = dealSelectData(data);
		$("#studentInfo").autocomplete( {
			source : data,
			select : function(event, ui) {
				$("#attendanceStudentName").html(ui.item.studentName);
				$("#attendanceStudentNameId").show()
				studentName = ui.item.studentName;
				studentNumber = ui.item.studentNumber; 
				return false;
			}
		}).data("autocomplete")._renderItem = function(ul, item) {
			return $("<li></li>").data("item.autocomplete", item).append(
					"<a>" + item.studentNumber + "<" + item.studentName
							+ "></a>").appendTo(ul);
		}
	})
}
function dealSelectData(data) {
	var stuList = [];
	$(data).each(function(index, item) {
		var stuInfo = {};
		stuInfo.studentName = item.studentName;
		stuInfo.studentNumber = item.studentNumber;
		stuInfo.value = item.studentNumber;
		stuInfo.label = item.studentNumber + " " + item.studentName;
		stuList.push(stuInfo);
	})
	return stuList;
}
/*调出DIV层*/
function attendanceImportBut() {
	if (className != null) {
		attendanceImport(studentNumber);
	} else {
		alert("请您一定输入班级名称!");
	}
}

/*导入一行数据*/
function attendanceImportData(studentNumber, weekCount, lateCount,
		leaveEarlyCount, truancyCount, leaveCount) {
	var isPoInteger = /^\s*[0-9]+\s*$/;//判断是否为数字
	var weekCounts = weekCount;
	var lateCounts = lateCount;
	var leaveEarlyCounts = leaveEarlyCount;
	var truancyCounts = truancyCount;
	var leaveCounts = leaveCount;
	if (weekCounts > 0 && isPoInteger.test(weekCounts)
			&& isPoInteger.test(lateCounts)
			&& isPoInteger.test(leaveEarlyCounts)
			&& isPoInteger.test(truancyCounts) && isPoInteger.test(leaveCounts)) {
		//如果这一周已经存在数据就不能再添加，只能修改数据
		//alert("学号:"+studentNumber+",周次" + weekCounts + ",迟到:" + lateCounts + ",早退:" + leaveEarlyCounts + ",请假:"+ leaveCounts + ",旷课:" + truancyCounts);
		attendanceAction.isRepeatWeek(weekCounts, studentNumber, function(data) {
					//alert(weeks);
						//alert(studentNumber);
						//alert(data);
						if (data) {
							attendanceAction
									.addAttendanceRecord(
											studentNumber,
											weekCounts,
											lateCounts,
											leaveEarlyCounts,
											truancyCounts,
											leaveCounts,
											function() {
												$("#waitDiv").show();
												alert("导入成功");
												$("#resultDiv").show();
												lineNumber = $("table#result tr").length;
												$("#result")
														.append(
																insertTr(
																		lineNumber,
																		weekCounts,
																		className,
																		studentNumber,
																		studentName,
																		lateCounts,
																		truancyCounts,
																		leaveEarlyCounts,
																		leaveCounts));
											});
						} else {
							alert("您输入的周次已经存在，请再指定的周次修改数据，不能重新增加!");
						}
					});
	} else {
		alert("请输入数字，并核对数据!");
		return;
	}
	//$("#waitDiv").hide();
	setTimeout(function() {
		$("#waitDiv").hide();
	}, 400);
	//alert(lineNumber);
}

/*插入一行*/
function insertTr(lineNumber, weekCounts, className, studentNumber,
		studentName, lateCounts, truancyCounts, leaveEarlyCounts, leaveCounts) {
	//$("table#result tr:gt(0)").remove();
	$("#dataId").html(lineNumber);
	$("#allDataDiv").show();
	var tr = "<tr id='InputId'><td>" + lineNumber + "</td><td>" + weekCounts
			+ "</td><td>" + className + "</td><td>" + studentNumber
			+ "</td><td>" + studentName + "</td><td>" + lateCounts
			+ "</td><td>" + truancyCounts + "</td><td>" + leaveEarlyCounts
			+ "</td><td>" + leaveCounts + "</td></tr>";
	return tr;
}
document.onkeydown = function(event) {
	if($.trim($("#studentInfo").val())!=""){
		event = event ? event : window.event
		if (event.keyCode == 13) {
			$("#importButton").trigger("click")
		}
	}
}
</script>
	</head>
	<body>
		<jsp:include page="../common/header.jsp"></jsp:include>

		<div id="menu">
			<div id="mainMenuDiv">
				<ul>
					<li>
						<a href="web/teacherSearch.jsp">教师信息管理</a>
					</li>
					<li>
						<a href="#">学生信息管理</a>
					</li>
					<li>
						<a href="web/studentInformationBasic.jsp">个人信息管理</a>
					</li>
					<li>
						<a href="web/logisticsSearchDorm.jsp">后勤管理</a>
					</li>
					<li>
						<a href="web/scoreSearch.jsp">成绩管理</a>
					</li>
					<li>
						<a href="web/attendanceSearch.jsp">考勤管理</a>
					</li>
				</ul>
			</div>

			<div id="minorMeun">
				<ul>
					<li>
						<a href="web/attendanceSearch.jsp">考勤查询</a>
					</li>
					<li>
						<a href="web/attendanceImport.jsp">考勤导入</a>
					</li>
				</ul>
			</div>

		</div>
		<div id="bodyDiv">
			<div id="bodyTitleDiv">
				<div id="breadcrumbDiv">
					当前位置
					<a href="web/index.jsp">：首页</a>&gt;
					<a href="web/logisticsSearchDorm.jsp">考勤管理</a>&gt;
					<a href="web/logisticsSearchDorm.jsp">考勤导入</a>
				</div>
			</div>
			<div id="bodyCentreDiv">
				<div id="conditionDiv">
					<table>
						<tr>
							<td>

								班&nbsp;&nbsp;&nbsp;&nbsp;级:
								<input type="text" id="className" size="10" maxlength="20"/>
							</td>
							<td>
								&nbsp;&nbsp;&nbsp;&nbsp;学&nbsp;&nbsp;&nbsp;&nbsp;号:
								<input type="text" size="10" maxlength="15" id="studentInfo"
									onclick="initStudentSelect()" />
							</td>
							<td style="display: none" id="attendanceStudentNameId">
								&nbsp;&nbsp;&nbsp;&nbsp;姓名：
								<samp id="attendanceStudentName" style="font-weight: bold;">
								</samp>
							</td>
						</tr>

					</table>

				</div>
				<div id="waitDiv" style="display: none">
					<img src="images/loading1.gif" />
					导入中...
				</div>
				<div id="buttonDiv">
					<input name="" type="button" value="导入"
						onclick="attendanceImportBut()"  id="importButton"/>
				</div>

				<div id="attendancImportDiv" title="导入" style="display: none;">
					<table border="0" cellspacing="10" class="table_popup1">
						<tr>
							<td>
								周&nbsp;&nbsp;&nbsp;&nbsp;次:
							</td>
							<td class="table_writed1">
								<input id="weekId" type="text" size="5" maxlength="3" value="0" />
							</td>
						</tr>
						<tr>
							<td>
								迟&nbsp;&nbsp;&nbsp;&nbsp;到:
							</td>
							<td class="table_writed2">
								<input id="lateId" type="text" size="5" maxlength="3" value="0" />
							</td>
							<td>
								早&nbsp;&nbsp;&nbsp;&nbsp;退:
							</td>
							<td class="table_writed3">
								<input id="leaveEarlyId" type="text" size="5" maxlength="3"
									value="0" />
							</td>
						</tr>
						<tr>
							<td>
								旷&nbsp;&nbsp;&nbsp;&nbsp;课:
							</td>
							<td class="table_writed4">
								<input id="truancyId" type="text" size="5" maxlength="3"
									value="0" />
							</td>
							<td>
								请&nbsp;&nbsp;&nbsp;&nbsp;假:
							</td>
							<td class="table_writed5">
								<input id="leaveId" type="text" size="5" maxlength="3" value="0" />
							</td>
						</tr>
					</table>
				</div>

				<div id="resultDiv" style="display:none;">
					<div id="resultTitleDiv">
						导入结果：
					</div>
					<div id="resultDataDiv">
						<table cellspacing="1" class="contentTable" id="result">
							<tr>
								<th>
									序号
								</th>
								<th>
									周次
								</th>
								<th>
									班级
								</th>
								<th>
									学号
								</th>
								<th>
									姓名
								</th>
								<th>
									迟到
								</th>
								<th>
									旷课
								</th>
								<th>
									早退
								</th>
								<th>
									请假
								</th>
							</tr>
							
						</table>
						<div id="allDataDiv" style="display: none">
							共
							<samp id="dataId">
								1
							</samp>
							条数据
						</div>
						<!--<div id="allDataDiv">
							共
							<samp>
								10
							</samp>
							页&nbsp;&nbsp;共
							<samp>
								100
							</samp>
							条数据
						</div>-->
						<!--<div id="pagingD">
							<a href="#">上一页</a>
							<a href="#">1</a>
							<a href="#">2</a>
							<a href="#">3</a>
							<a href="#">下一页</a>
							<select name="">
								<option>
									页数
								</option>
								<option>
									1
								</option>
								<option>
									2
								</option>
								<option>
									3
								</option>
								<option>
									4
								</option>
								<option>
									5
								</option>
								<option>
									6
								</option>
								<option>
									7
								</option>
								<option>
									8
								</option>
							</select>
							<input name="" type="button" value="跳转" id="skipBut" />
						</div>-->
					</div>
				</div>
			</div>
		</div>


		<jsp:include page="../common/footer.jsp"></jsp:include>
	</body>
</html>

